/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Administrator.java
 *
 * Created on Oct 11, 2010, 11:40:25 AM
 */

package cat20032010;

import java.sql.*;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Daniel Tan
 */
public class Administrator extends javax.swing.JPanel {
     static public String newordername,newordercode,neworderprice;
    /** Creates new form Administrator */
    
    Vector data = new Vector();
    Vector columnNames = new Vector();
    static Statement stmt;
    private static ResultSet rset;

    static EditMenuList EditMenuList = new EditMenuList();
    static Admin_Add Admin_Add = new Admin_Add();
    static DeleteMenuList DeleteMenuList = new DeleteMenuList();
    public Administrator() {
        initComponents();
        getdata();
    }

    
    public static void getdata()
    {
        Vector data = new Vector();
        Vector columnNames = new Vector();
        try {
            Main.getConnection();
            stmt = Main.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

            rset = stmt.executeQuery("SELECT MENU_CODE AS CODE, MENU_NAME AS NAME, to_char(MENU_PRICE,'99,999.99') AS PRICE FROM MENU ORDER BY MENU_CODE");
            rset.first();

            ResultSetMetaData md = rset.getMetaData();
            int columns = md.getColumnCount();

            //  Get column names

            for (int i = 1; i <= columns; i++) {
                columnNames.addElement(md.getColumnName(i));
            }

            rset.first();

            if (rset.isFirst() == true) {
                // JOptionPane.showMessageDialog(null, "Hello");
                Vector row = new Vector(columns);

                for (int i = 1; i <= columns; i++) {
                    row.addElement(rset.getString(i));
                }

                data.addElement(row);
            }else{
                System.out.print("sssssaaaaaaaaaaaaa");
                JOptionPane.showMessageDialog(null, "No Record Found!", "MESSAGE!", JOptionPane.INFORMATION_MESSAGE);
            }


            if (rset.isFirst() == true && rset.isLast() == true) {
                // JOptionPane.showMessageDialog(null, "Hello");
                Vector row = new Vector(columns);

                for (int i = 1; i <= columns; i++) {
                    row.addElement(rset.getString(i));
                }

                data.addElement(row);
            } else {
                while (rset.next()) {
                    // rset.next();
                    Vector row = new Vector(columns);

                    for (int i = 1; i <= columns; i++) {
                        row.addElement(rset.getString(i));
                    }

                    data.addElement(row);
                }
            }
        }
            catch (SQLException e) {
                System.out.println("fail");
            }

        DefaultTableModel model = new DefaultTableModel(data, columnNames)
       {
        public boolean isCellEditable(int row,int column){
            return false;

        }
    };
        jTable1.setModel(model);


    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        viewtoggle = new javax.swing.JToggleButton();
        addtoggle = new javax.swing.JToggleButton();
        edittoggle = new javax.swing.JToggleButton();
        deletetoggle = new javax.swing.JToggleButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Administrator", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 24), new java.awt.Color(0, 0, 0))); // NOI18N
        jPanel1.setLayout(null);

        viewtoggle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button/view.png"))); // NOI18N
        viewtoggle.setSelected(true);
        viewtoggle.setBorderPainted(false);
        viewtoggle.setContentAreaFilled(false);
        viewtoggle.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/button/viewselect.png"))); // NOI18N
        viewtoggle.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/button/viewpressed.png"))); // NOI18N
        viewtoggle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewtoggleActionPerformed(evt);
            }
        });
        jPanel1.add(viewtoggle);
        viewtoggle.setBounds(30, 50, 110, 55);

        addtoggle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button/add.png"))); // NOI18N
        addtoggle.setBorderPainted(false);
        addtoggle.setContentAreaFilled(false);
        addtoggle.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/button/addselect.png"))); // NOI18N
        addtoggle.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/cat20032010/addpressed.png"))); // NOI18N
        addtoggle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addtoggleActionPerformed(evt);
            }
        });
        jPanel1.add(addtoggle);
        addtoggle.setBounds(30, 110, 110, 55);

        edittoggle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button/edit1.png"))); // NOI18N
        edittoggle.setBorderPainted(false);
        edittoggle.setContentAreaFilled(false);
        edittoggle.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/button/editselect1.png"))); // NOI18N
        edittoggle.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/button/editpressed1.png"))); // NOI18N
        edittoggle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                edittoggleActionPerformed(evt);
            }
        });
        jPanel1.add(edittoggle);
        edittoggle.setBounds(30, 170, 110, 55);

        deletetoggle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button/delete.png"))); // NOI18N
        deletetoggle.setBorderPainted(false);
        deletetoggle.setContentAreaFilled(false);
        deletetoggle.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/button/deleteselect.png"))); // NOI18N
        deletetoggle.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/button/deletepressed.png"))); // NOI18N
        deletetoggle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deletetoggleActionPerformed(evt);
            }
        });
        jPanel1.add(deletetoggle);
        deletetoggle.setBounds(30, 230, 110, 55);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jPanel1.add(jScrollPane1);
        jScrollPane1.setBounds(160, 50, 452, 360);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void viewtoggleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewtoggleActionPerformed
        viewtoggle.setSelected(true);
        addtoggle.setSelected(false);
        edittoggle.setSelected(false);
        deletetoggle.setSelected(false);
        getdata();
        EditMenuList.setVisible(false);
        Admin_Add.setVisible(false);
        DeleteMenuList.setVisible(false);
    }//GEN-LAST:event_viewtoggleActionPerformed

    private void addtoggleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addtoggleActionPerformed
        Admin_Add = new Admin_Add();
        viewtoggle.setSelected(false);
        addtoggle.setSelected(true);
        edittoggle.setSelected(false);
        deletetoggle.setSelected(false);
        Admin_Add.setVisible(true);
        EditMenuList.setVisible(false);
        DeleteMenuList.setVisible(false);
    }//GEN-LAST:event_addtoggleActionPerformed

    private void edittoggleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_edittoggleActionPerformed
        EditMenuList = new EditMenuList();
        viewtoggle.setSelected(false);
        addtoggle.setSelected(false);
        edittoggle.setSelected(true);
        deletetoggle.setSelected(false);
        EditMenuList.setVisible(true);
        Admin_Add.setVisible(false);
        DeleteMenuList.setVisible(false);
    }//GEN-LAST:event_edittoggleActionPerformed

    private void deletetoggleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deletetoggleActionPerformed
        
        DeleteMenuList = new DeleteMenuList();
        viewtoggle.setSelected(false);
        addtoggle.setSelected(false);
        edittoggle.setSelected(false);
        deletetoggle.setSelected(true);
        EditMenuList.setVisible(false);
        Admin_Add.setVisible(false);
        DeleteMenuList.setVisible(true);
    }//GEN-LAST:event_deletetoggleActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToggleButton addtoggle;
    private javax.swing.JToggleButton deletetoggle;
    private javax.swing.JToggleButton edittoggle;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private static javax.swing.JTable jTable1;
    private javax.swing.JToggleButton viewtoggle;
    // End of variables declaration//GEN-END:variables

}
